package yesjava;

import java.io.*;
//  2
public class MainWrite {
    public static void main(String[] args) throws Exception {
        File file = new File("D://dogFile");
        if (file.exists()) {
            file.delete();
        }
        file.createNewFile();
        OutputStream out = new FileOutputStream(file);
        ObjectOutputStream bos = new ObjectOutputStream(out);
        for (int i = 1; i <=
                8; i++) {
            Dog dog = new Dog("红色"+i, "旺财"+i, Math.random()>=0.5?true:false);//0011011101011011
            bos.writeObject(dog);
        }
        bos.flush();
        bos.close();
        System.out.println("已经序列化N个对象");
    }
}



  /* if(dog1 instanceof Serializable){
            System.out.println("允许土葬");
        }else{
            System.out.println("只能火葬");
            throw new NotSerializableException(dog1.getClass().getName()+"  类型不允许序列化");
        }*/